<template>
    <el-form>
        
        <p>基础用法</p>
        <el-checkbox v-model="checked" @change="checkedChange">备选项</el-checkbox>
        
        <p>禁用用法</p>
        <el-checkbox v-model="checked1" disabled>禁用1</el-checkbox>
        <el-checkbox v-model="checked2" disabled>禁用2</el-checkbox>
     
        
        <p>多选框组</p>
        <el-checkbox-group v-model="checkList">
            <el-checkbox label="复选框A"></el-checkbox>
            <el-checkbox label="复选框B"></el-checkbox>
            <el-checkbox label="复选框C"></el-checkbox>
            <el-checkbox label="禁用" disabled></el-checkbox>
            <el-checkbox label="选中且禁用" disabled></el-checkbox>
        </el-checkbox-group>
  
        <p>indeterminate状态</p>
        <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
        <div style="margin: 15px 0;"></div>
        <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
            <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>
        </el-checkbox-group>
        
        <p>可选项目数量的限制</p>
        <el-checkbox-group v-model="checkedCities" :min="1" :max="2" >
            <el-checkbox v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox>
        </el-checkbox-group>

        <p>按钮样式</p>
        <div>
            <el-checkbox-group v-model="checkboxGroup1">
                <el-checkbox-button v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox-button>
            </el-checkbox-group>
        </div>

        <div style="margin-top: 20px;">
            <el-checkbox-group v-model="checkboxGroup2" size="medium">
                <el-checkbox-button v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox-button>
            </el-checkbox-group>
        </div>
        <div style="margin-top: 20px;">
            <el-checkbox-group v-model="checkboxGroup3" size="small" fill="#FF0000">
                <el-checkbox-button v-for="city in cities" :label="city" :disabled="city==='北京'" :key="city">{{ city }}</el-checkbox-button>
            </el-checkbox-group>
        </div>
        <div style="margin-top: 20px;">
            <el-checkbox-group v-model="checkboxGroup4" size="mini" disabled>
                <el-checkbox-button v-for="city in cities" :label="city" :key="city">{{ city }}</el-checkbox-button>
            </el-checkbox-group>
        </div>
        <p>带有边框</p>
        <div style="margin-top: 20px;">
            <el-checkbox v-model="checked1" label="1" border></el-checkbox>
            <el-checkbox v-model="checked2" label="2" border></el-checkbox>
        </div>
        <div style="margin-top: 20px;">
            <el-checkbox v-model="checked1" label="1" border size="medium"></el-checkbox>
            <el-checkbox v-model="checked2" label="2" border size="medium"></el-checkbox>
        </div>
        <div style="margin-top: 20px;">
            <el-checkbox-group v-model="checkboxGroup1" size="small">
                <el-checkbox label="1" border></el-checkbox>
                <el-checkbox label="2" border disabled></el-checkbox>
            </el-checkbox-group>
        </div>
        <div style="margin-top: 20px;">
            <el-checkbox-group v-model="checkboxGroup2" size="mini" disabled>
                <el-checkbox label="上海" border></el-checkbox>
                <el-checkbox label="2" border ></el-checkbox>
            </el-checkbox-group>
        </div>
    </el-form>
</template>

<script>
    const cityOptions=['上海','北京','广州','深圳'];
    export default{
        data() {
            return{
                checked:true,

                checked1:false,
                checked2:true,

                checkList:['复选框A','选中且禁用'],

                checkAll:false,
                checkedCities:['上海','北京'],
                cities:cityOptions,
                isIndeterminate:true,

                checkboxGroup1: ['上海'],
                checkboxGroup2: ['上海'],
                checkboxGroup3: ['上海'],
                checkboxGroup4: ['上海'],

            };
        },
        methods:{
            checkedChange(val){
                console.log('传入的值是:',val);
            },
            handleCheckAllChange(val){
                this.checkedCities=val?cityOptions:[];
                this.isIndeterminate=false;
            },
            handleCheckedCitiesChange(val){
                let checkedCount=val.length;
                this.checkAll=checkedCount===this.cities.length;
                this.isIndeterminate=checkedCount>0&& checkedCount<this.cities.length;
            }
    
        }
    
    }
</script>